package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.UserSynthesisRecord;
import com.sc.nft.entity.vo.AdminSynthesisRecordSimpleVO;
import com.sc.nft.entity.vo.AdminSynthesisRecordVO;
import com.sc.nft.entity.vo.SynthesisRecordVO;
import com.sc.nft.mapper.UserSynthesisRecordMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * (sc_user_synthesis_record)数据DAO
 *
 * @author rdg
 * @since 2022-06-28 19:53:02
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserSynthesisRecordDao extends ServiceImpl<UserSynthesisRecordMapper, UserSynthesisRecord> {

    public List<SynthesisRecordVO> synthesisRecord( Long userId) {
        return baseMapper.synthesisRecord(userId);
    }

    public Page<AdminSynthesisRecordVO> adminSynthesisRecord(int pageNo, int pageSize, String nickName, String userTel, String firstTitle, Date startDate, Date endDate) {
        return baseMapper.adminSynthesisRecord(new Page(pageNo,pageSize),nickName,userTel,firstTitle,startDate,endDate);
    }

    public List<AdminSynthesisRecordSimpleVO> adminSynthesisRecordExport(Long productId, Date startDate, Date endDate) {
        return baseMapper.adminSynthesisRecordExport(productId,startDate,endDate);
    }

    public Integer getCountByUserIdAndProductId(Long userId, Long productId) {
        return baseMapper.getCountByUserIdAndProductId(userId,productId);

    }


    /**
     * @param start   起始条目
     * @param end     结束条目
     * @param orderId 查询区间订单号
     * @return
     */
    public Integer findLimitBetween(Long start, Long end, Long orderId,Integer collectionId) {
        return baseMapper.findLimitBetween(start, end, orderId,collectionId);
    }
    public Integer findLimitBetweenSum( Integer collectionId) {
        return baseMapper.findLimitBetweenSum(collectionId);
    }



    public List<UserSynthesisRecord> compensation(Integer start, Integer end,Long collectionId) {
        return baseMapper.compensation(start, end,collectionId);
    }

    public Integer getYesterDayCountByCollectionId(Long collectionId) {
        return baseMapper.getYesterDayCountByCollectionId(collectionId);
    }

    public Integer getYesterDayCountByCollectionIdByDay(Long collectionId,String day) {
        return baseMapper.getYesterDayCountByCollectionIdByDay(collectionId,day);
    }

    public Integer getSumCountByCollectionId(List<Long> collectionId) {
        return baseMapper.getSumCountByCollectionId(collectionId);
    }

    public Integer getCountByUserIdAndCollectionId(Long userId, Long collectionId) {
        LambdaQueryWrapper<UserSynthesisRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserSynthesisRecord::getUserId,userId);
        wrapper.eq(UserSynthesisRecord::getCollectionId,collectionId);
        return count(wrapper);
    }
}